package collection;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * 说明:
 *
 * @author:SuZhongHe
 * @date:2023/3/3
 **/
public class ListDemo {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("a");
        list.add("b");
        list.add("c");
        list.add("d");
        list.add("e");
        Iterator<String> it = list.iterator();
        System.out.println("----迭代器遍历------");
        while (it.hasNext()) {
            String next =  it.next();
            System.out.println(next);

        }
        System.out.println("------for遍历---------");
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        System.out.println("---------增强for遍历-----------");
        for (String s : list) {
            System.out.println(s);
        }
        System.out.println("-----修改下标2------");
        String s = list.set(2,"666");
        System.out.println(s);
        System.out.println(list);
        System.out.println("删除下标2---------------");

          list.remove(2);
        System.out.println(list);
        System.out.println("------根据下标插入---------");
        list.add(3,"777");


    }
}
